package cn.db.tools.dbtools.controller;

import cn.db.tools.dbtools.message.ToastMessage;
import com.google.common.hash.Hashing;
import com.google.common.io.BaseEncoding;
import com.google.common.io.Files;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser;
import org.pomo.toasterfx.model.impl.ToastTypes;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @author：zooooooooy
 * @date: 2023/8/9 - 18:10
 */
public class PrettyJsonController implements Initializable {

    @FXML
    private TextArea base64TextSource;

    @FXML
    private TextArea base64TextTarget;


    @Override
    public void initialize(URL location, ResourceBundle resources) {

        base64TextSource.setWrapText(true);
        base64TextTarget.setWrapText(true);
    }

    @FXML
    protected void originTextChanged() {

        base64TextTarget.setText(new GsonBuilder()
                .setPrettyPrinting()
                .create()
                .toJson(JsonParser.parseString(base64TextSource.getText())
                        .getAsJsonObject()));

    }

    @FXML
    protected void copyTextFieldBase64() {
        Clipboard sc = Clipboard.getSystemClipboard();
        ClipboardContent clipboardContent = new ClipboardContent();
        clipboardContent.put(DataFormat.PLAIN_TEXT, base64TextTarget.getText());

        sc.setContent(clipboardContent);
        // 弹出toast消息
        ToastMessage.getInstance().popMessage("复制成功", ToastTypes.SUCCESS);
    }
}
